<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css"/>
    <style>
        .layui-form-select dl{
            max-height: 180px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" style="padding-right: 30px">
    <div class="main-container">
        <div class="layui-row layui-col-space1">
            <div class="layui-col-md12">
                <input type="hidden" id="id" name="id" value="${taskCron.id!}">
                <div class="layui-form-item">
                    <div class="layui-col-md12">
                        <label class="layui-form-label required">task名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="task" readonly lay-verify="required" required placeholder="" autocomplete="off"
                                   class="layui-input" value="${taskCron.task!}">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-xs8">
                        <label class="layui-form-label required">频率</label>
                         <input type="number" name="time" style="width: 50%!important;" lay-verify="required|timeCheck" required placeholder="" autocomplete="off"
                               class="layui-input" value="${taskCron.time!}">
                    </div>
                    <div class="layui-col-xs4">
                        <select name="pl" id="pl" lay-verify="required" >
                            <option value="" selected>请选择</option>
                            <option value="hour" ${taskCron.pl!0=='hour'?'selected':''}>小时</option>
                            <option value="minute" ${taskCron.pl!0=='minute'?'selected':''}>分钟</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md12">
                        <label class="layui-form-label required">开关</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" if(${(taskCron.status!)}==''){ checked } ${(taskCron.status!)=='true'?'checked':''} value="true" title="开">
                            <input type="radio" name="status" ${(taskCron.status!)=='false'?'checked':''} value="false" title="关">
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="task-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
        </div>
    </div>

</form>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use('form', function () {
        var form = layui.form
        $ = layui.$;
    });

</script>
<script>
    layui.use(['form', 'jquery', 'select', 'code', 'element'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let DATA_PATH = "${ctxPath}/video/data/";
        let select = layui.select;

        layui.code();

        form.verify({
            timeCheck:function(value){
                let pl = $("#pl").val();
                if (pl=="hour"){
                    if (value>24 || value<0){
                        return '请输入0-24范围内的数字';
                    }
                }else if (pl=='minute'){
                    if (value>60 || value<0){
                        return '请输入0-60范围内的数字';
                    }
                }

            }
        });

        form.on('submit(task-save)', function (data) {
            $.ajax({
                url: DATA_PATH + 'saveOrUpdate',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code == 0) {
                        layer.msg("操作成功", {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        });
                    } else {
                        layer.msg("操作失败", {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>